package view 
{
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import model.GameData;
	import model.MyData;
	/**
	 * ...
	 * @author bimkute
	 */
	public class DialLucky extends Base 
	{
		//private var _dialing:MovieClip;
		private var _arrDialing:Array = [];
		private var _arrTop:Array = [];
		
		private var _arrNumberDialing:Array = [];
		
		
		private var _totalSum:MovieClip;
		
		private var _count:int = 0;
		
		private var i:int;
		private var j:int;
		
		public function DialLucky() 
		{
			_totalSum = getImage("bg_bangthantai", "playGame");
			addChild(_totalSum);
			_totalSum.x = 500;
			_totalSum.y = 120;
			
			var arr:Array = [20, 10, 5];
			var arr1:Array = ["TOP PLAYER 10", "TOP PLAYER 20", "TOP PLAYER 30"];
			
			for (i = 0; i < 3; i++) 
			{
				var spin:Spin = new Spin(arr[i]);
				addChild(spin);
				
				spin.x = 300 + i * (spin.width + 70);
				spin.y = 230;
				
				//spin.scaleX = spin.scaleY = .75;
				//mảng chứa các dialing
				_arrDialing.push(spin);
				
				
				var topPlayer:TopPlayers = new TopPlayers(arr1[i]);
				addChild(topPlayer);
				topPlayer.x = 275 + i * (topPlayer.width + 20);
				topPlayer.y = 470;
				
			}
			
			for (i = 0; i < 7; i++) 
			{
				_totalSum["txt_num" + String(i + 1)].text = "0";
			}
			
			GameData.getInstance().addEventListener("quithantai", getTotalMoneyToday );
		}
		
		private function getTotalMoneyToday(e:Event):void 
		{
			var str:String = "";
			var totalMoney:int = GameData.getInstance().totalMoneyToday;
			var arr:Array = [];
			totalMoney = 62;
			for (i = 0; i < 7 - String(totalMoney).length; i++) 
			{
				str += "0";
			}
			trace("1: ", str)
			str += String(totalMoney);
			trace("2: ", str)
			for (i = 0; i < 7; i++) 
			{
				arr.push(_totalSum["txt_num" + String(i + 1)]);
			}
			
			for (i = 0; i < 7; i++) 
			{
				
				arr[i].text = str.charAt(i);
			}
		}
		
		public function getDialing(arrNumberDialing:Array):void
		{
			
			_arrNumberDialing = arrNumberDialing;
			var timer:Timer = new Timer(1000, 3);
			timer.addEventListener(TimerEvent.TIMER, onTimer);
			timer.start();
			
		}
		
		private function onTimer(e:TimerEvent):void 
		{
			trace("_arrNumberDialing", _arrNumberDialing)
			_arrDialing[_count].dial(_arrNumberDialing[_count]);
			_count++;
		}
		
		public function removeAllEvent():void
		{
			
		}
	}

}